<template>
  <div>
    <userTitel :title="title"></userTitel>

    <!-- 卡片 -->
    <el-card shadow="never">
      <el-row>
        <el-button type="primary" @click="showDialog = true"
          >添加工作模式</el-button
        >
      </el-row>
      <!-- 表格 -->
      <el-table
        border
        :data="tableData"
        stripe
        style="width: 100%; margin-top: 20px"
      >
        <el-table-column prop="id" label="工作模式编号"> </el-table-column>
        <el-table-column prop="name" label="工作模式"> </el-table-column>
        <el-table-column prop="workPatternTypeDesc" label="类型">
        </el-table-column>
        <el-table-column prop="workDate" label="工作日期"> </el-table-column>
        <el-table-column label="工作时间">
          <template #default="{ row }">
            <span>{{ row.workEndMinute1 }}小时</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="{ row }">
            <el-link style="color: #419eff" @click="edit(row)">编辑</el-link>
            <span style="color: #dcdfe6"> | </span>
            <el-link type="primary" @click="del(row.id)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-row type="flex" justify="center" style="margin-top: 20px">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="+total"
        >
        </el-pagination>
      </el-row>
    </el-card>
    <!-- 新增工作模式弹框 -->
    <el-dialog width="40%" title="新增工作模式" :visible.sync="showDialog">
      <el-tabs
        v-model="activeName"
        @tab-click="handleClick"
        style="padding-left: 20px; padding-right: 20px"
      >
        <el-tab-pane label="礼拜制" name="first">
          <el-form>
            <el-form-item label="工作模式名称 :">
              <el-input v-model="addWork.name" style="width: 450px"></el-input>
            </el-form-item>
            <!-- 多选框 -->
            <el-form-item label="连续工作天数 :">
              <el-checkbox-group
                v-model="addWork.workDate"
                @change="handleCheckedCitiesChange"
              >
                <el-checkbox v-for="city in cities" :label="city" :key="city">
                  {{ city }}
                </el-checkbox>
              </el-checkbox-group>
              <p style="color: #bec4d0; margin-top: -20px">
                选中为工作时间,未选中为休息时间
              </p>
            </el-form-item>
            <!-- 工作时间 -->
            <el-form-item label="工作时间 :">
              <el-time-picker
                style="width: 450px"
                is-range
                v-model="value1"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                placeholder="选择时间范围"
              >
              </el-time-picker>
            </el-form-item>
            <el-form-item>
              <el-row type="flex" justify="center">
                <el-button type="primary" @click="addSubmit('week')"
                  >确认</el-button
                >
                <el-button>取消</el-button>
              </el-row>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="连续制" name="second">
          <el-form>
            <el-form-item label="工作模式名称 :">
              <el-input
                placeholder="请输入工作模式名称"
                style="width: 450px"
              ></el-input>
            </el-form-item>
            <!-- 多选框 -->
            <el-form-item label="连续工作天数 :">
              <span style="margin-right: 10px">上</span>
              <el-input style="width: 110px" placeholder="请输入">
                <!-- suffix-icon="el-icon-date" -->
                <span slot="suffix" style="color: #333; margin-right: 10px"
                  >天</span
                >
              </el-input>
              <!-- 休 -->
              <span style="margin-right: 10px; margin-left: 20px">休</span>
              <el-input style="width: 110px" placeholder="请输入">
                <!-- suffix-icon="el-icon-date" -->
                <span slot="suffix" style="color: #333; margin-right: 10px"
                  >天</span
                >
              </el-input>
            </el-form-item>
            <!-- 工作时间 -->
            <el-form-item label="工作时间 :">
              <el-time-picker
                style="width: 450px"
                is-range
                v-model="value1"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                placeholder="选择时间范围"
              >
              </el-time-picker>
            </el-form-item>
            <el-form-item>
              <el-row type="flex" justify="center">
                <el-button type="primary" @click="addSubmit('link')"
                  >确认</el-button
                >
                <el-button>取消</el-button>
              </el-row>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
  </div>
</template>

<script>
import { getModel, addWorkUser, deleteCount } from "@/api/workArrange-manage";
export default {
  name: "workArrange-setting",
  data() {
    return {
      // 新增工作
      addWork: {
        friday: 1, //周五
        monday: 1, //周一
        name: "", //名称
        operator: 0, //操作人
        restDayNum: 0, //休息天数
        saturday: 1, //周六
        sunday: 1, //周日
        thursday: 1, //周四
        tuesday: 1, //周二
        userType: "",
        wednesday: 1, //周三
        workDayNum: 0, //连续工作天数
        workEndMinute1: 0, //工作结束时间 分钟
        workPatternType: "", //
        workStartMinute1: 0, //工作开始时间
        workDate: [], //选中的放进数组
      },
      // 时间
      value1: [new Date(2016, 9, 10, 9, 0), new Date(2016, 9, 10, 18, 0)],
      // 新增工作对选框
      // cities: [], //默认选中
      cities: [
        "周一", //一
        "周二", //二
        "周三", //三
        "周四", //四
        "周五", //五
        "周六", //六
        "周日", //日
      ],
      //弹框切换tab
      activeName: "first",
      // 弹框
      showDialog: false,
      title: "排班设置",
      //   表格列表
      tableData: [],
      currentPage4: 1,
      page: {
        page: 1,
        pageSize: 10,
      },
      total: 0, //总条数
    };
  },

  created() {
    this.isModule();
    // this.cities = this.cities.map((item, index) => {
    //   // console.log(item);
    //   for (let k in mapObj) {
    //     if (index == k) {
    //       return (item = mapObj[k]);
    //     }
    //   }
    // });
  },
  beforeCreate() {},

  methods: {
    // 获取工作模式列表
    async isModule() {
      const res = await getModel(this.page);
      console.log(res.data);
      this.total = res.data.counts; //总条目
      this.tableData = res.data.items;
      res.data.items.forEach((item) => {
        item.workEndMinute1 = (item.workEndMinute1 / 60).toFixed(2);
      });
      console.log(this.tableData);
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.page.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page.page = val;
    },
    // tab切换
    handleClick(tab, event) {
      console.log(tab.index, event);
    },
    // 连续工作天数
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.cities.length;
    },
    // 新增工作模式
    async addSubmit(value) {
      console.log(value);
      if (value === "week") {
        const res = await addWorkUser(this.addWork);
        console.log(res);
      }
    },
    // // 多选框
    // change(bool) {
    //   console.log(bool);
    // },
    // 编辑回显
    edit(row) {
      console.log(row);
    },
    // 删除
    async del(id) {
      // console.log(id);
      await deleteCount(id);
      // console.log(res);
    },
  },
};
</script>

<style scoped lang="scss">
::v-deep .el-card {
  text-align: left;
  line-height: 24px;
}
::v-deep .el-dialog {
  text-align: left;
  line-height: 24px;
}
</style>
